﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using Optimization.Utilities;

namespace Optimization.StandardProblems
{
    [IsProblem]
    public class Beale : IProblem
    {
        int Dim = 2;

        public Beale()
        {
            this.Dim = 2;
        }

        public static double Evaluate(Vector v)
        {
            double x = v[0];
            double y = v[1];
            double xy = x * y;
            double z1 = 1.5 - x + xy;
            double z2 = 2.5 - x + xy * y;
            double z3 = 2.6525 - x + xy * y * y;
            double result = z1 * z1 + z2 * z2 + z3 * z3;

            return result;
        }

        double IProblem.Evaluate(Vector v)
        {
            return Beale.Evaluate(v);
        }
        
        void IProblem.GetBounds(out Vector mins, out Vector maxs)
        {
            mins = -5 * Vector.One(Dim);
            maxs = +5 * Vector.One(Dim);
        }

        bool IProblem.IsFeasible(Vector v)
        {
            return true;
        }

        Vector IProblem.RandomSolution()
        {
            Vector result = Vector.Random(Dim, -5, 5);
            return result;
        }
    }
}

